#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string a, b;
void preorder( int mb, int ml, int lb, int ll)
{
    if(ml == 1)
    {
        printf("%c", a[mb]);
        return;
    }else if(ml == 0)return;
    int i ;
    for(i = 0; i<ml; i++)
    {
        if(a[mb + i] == b[lb + ll -1])break;
    }
    printf("%c", a[mb + i]);
    preorder(mb, i, lb, i);
    preorder(mb + i + 1, ml - i - 1, lb + i, ml - i - 1);
}
int main()
{
    cin >> a >> b;
    preorder( 0, a.length(),0, b.length());
}
